package cn.ahaiahaixx.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.ahaiahaixx.config.MyConfig;
import cn.ahaiahaixx.entity.Greeting;
import cn.ahaiahaixx.entity.JsonMessage;

/**
 * Greeting控制器
 * 
 * @author Aiden Pearce
 *
 */
@RequestMapping("/greeting")
@ResponseBody
@RestController
public class GreetingController {
	@Autowired
	private MyConfig myconfig;

	@RequestMapping(name = "/index")
	public JsonMessage index() {
		// http://127.0.0.1:20000
		String m = String.format("欢迎使用springboot1,%s,%s", myconfig.appName, myconfig.reload);
		JsonMessage message = JsonMessage.getSuccess(m);
		return message;

	}

	@RequestMapping("/greeting")
	public JsonMessage greeting(Greeting greeting) {
		// http://127.0.0.1:8080/greeting
		// http://127.0.0.1:8080/greeting?id=100
		// http://127.0.0.1:8080/greeting?id=101&content=abc123
		JsonMessage message = JsonMessage.getSuccess("");
		message.getDatas().put("greeting", greeting);
		return message;
	}

}
